package rcp.iphex2.ui.knownsubstances;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

import rcp.iphex2.model.AreaAnnotation;


public class KnownSubstancesFilter extends ViewerFilter {

	private String searchString;

	public void setSearchText(String s) {
		// Search must be a substring of the existing value
		this.searchString = ".*" + s + ".*";
	}

	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {
		if (searchString == null || searchString.length() == 0) {
			return true;
		}
		AreaAnnotation areaAnnotation = (AreaAnnotation) element;
		if (areaAnnotation.getName().toLowerCase().matches(searchString.toLowerCase())) {
			return true;
		}
		if ((areaAnnotation.getDt()+"".toLowerCase()).matches(searchString.toLowerCase())) {
			return true;
		}
		if ((areaAnnotation.getRt()+"".toLowerCase()).matches(searchString.toLowerCase())) {
			return true;
		}

		return false;
	}
}